import smtplib
from email import encoders
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart


def send_info_from_email(message="", filenames=[]):
    smtp = smtplib.SMTP()

    # 连接邮箱服务器地址
    smtp.connect('smtp.qq.com')

    # 加入主题和附件，邮件体

    # 发件人地址及授权码
    username = '2634118472@qq.com'
    password = 'lzrycqeouyxvecfb'
    # receiver = "2634118472.whatahotdog@gmail.com"
    receiver = username
    # 创建邮件对象
    msg = MIMEMultipart()
    msg["Subject"] = message
    msg['From'] = username
    msg['To'] = receiver

    # 邮件内容
    body = ""
    msg.attach(MIMEText(body, "plain"))

    # 添加文件附件
    for filename in filenames:
        attachment = open(filename, 'rb')

        part = MIMEBase('application', 'octet-stream')
        part.set_payload(attachment.read())
        encoders.encode_base64(part)
        part.add_header('Content-Disposition', f'attachment; filename={filename}')
        msg.attach(part)

    # 发送邮件
    try:
        server = smtplib.SMTP("smtp.qq.com")
        server.starttls()
        server.login(username, password)
        server.sendmail(username, receiver, msg.as_string())
        server.quit()
        print("邮件提示发送成功")
    except smtplib.SMTPException as e:
        print("邮件发送失败:", e)